package com.ruoyi.teaching.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.Attendance;
import com.ruoyi.teaching.domain.vo.AttendanceBo;
import com.ruoyi.teaching.domain.vo.AttendanceMonthBo;
import com.ruoyi.teaching.service.IAttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.List;

/**
 * 考勤Controller
 *
 * @author wwh
 * @date 2024-02-19
 */
@RestController
@RequestMapping("/attendance")
public class AttendanceController extends BaseController
{
    @Autowired
    private IAttendanceService attendanceService;

    /**
     * 查询考勤列表
     */
    @RequiresPermissions("teaching:attendance:list")
    @GetMapping("/list")
    public TableDataInfo list(AttendanceBo attendanceBo)
    {

        List<AttendanceBo> list = attendanceService.selectAttendanceList(attendanceBo);
        return getDataTable(list);
    }

    /**
     * 查询全部考勤列表
     */
    @RequiresPermissions("teaching:attendance:list")
    @GetMapping("/listAll")
    public AjaxResult listAll(AttendanceBo attendanceBo)
    {
        AttendanceMonthBo attendanceMonthBo = attendanceService.selectAttendanceAllList(attendanceBo);
        return AjaxResult.success(attendanceMonthBo);
    }


    /**
     * 导出考勤列表
     */
    @RequiresPermissions("teaching:attendance:export")
    @Log(title = "考勤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Attendance attendance)
    {
//        List<Attendance> list = attendanceService.selectAttendanceList(attendance);
//        ExcelUtil<Attendance> util = new ExcelUtil<Attendance>(Attendance.class);
//        util.exportExcel(response, list, "考勤数据");
    }

    /**
     * 获取考勤详细信息
     */
    @RequiresPermissions("teaching:attendance:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(attendanceService.selectAttendanceById(id));
    }

    /**
     * 新增考勤
     */
    @RequiresPermissions("teaching:attendance:add")
    @Log(title = "考勤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Attendance attendance) throws ParseException {
        return toAjax(attendanceService.insertAttendance(attendance));
    }

    /**
     * 修改考勤
     */
    @RequiresPermissions("teaching:attendance:edit")
    @Log(title = "考勤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody List<AttendanceBo> attendanceBoList) throws ParseException {
        return toAjax(attendanceService.updateAttendance(attendanceBoList));
    }

    /**
     * 删除考勤
     */
    @RequiresPermissions("teaching:attendance:remove")
    @Log(title = "考勤", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attendanceService.deleteAttendanceByIds(ids));
    }
}
